package com.vcaresolution.logistic.dao;

import java.io.Serializable;
import java.util.List;

import org.hibernate.FetchMode;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.vcaresolution.logistic.pojo.City;
import com.vcaresolution.logistic.pojo.Country;
import com.vcaresolution.logistic.pojo.State;

/**
 * The <code>SectorDAO</code> class is a DAO Associated to do various 
 * options at DAO level for Sector
 *
 * @author Sneahl Shah
 * @version 1.0
 * @since ShipSoft 1.0
 */
@Repository
public class SectorDAO extends BaseDAO{

	@SuppressWarnings("unchecked")
	@Transactional
	public List<Country> getAssociatedCountryList(Serializable sectorId){
		List<Country> countryList = sessionFactory
										.getCurrentSession()
										.createCriteria(Country.class,"country")
										.createAlias("country.sector", "sector")
										.setFetchMode("sector", FetchMode.JOIN)
										.add(Restrictions.eq("sector.sectorid", sectorId))
										.list();
		
		return countryList;
	}
	
	@SuppressWarnings("unchecked")
	@Transactional
	public List<State> getAssociatedStateList(Serializable countryId){
		List<State> stateList = sessionFactory
										.getCurrentSession()
										.createCriteria(State.class,"state")
										.createAlias("state.country", "country")
										.setFetchMode("country", FetchMode.JOIN)
										.add(Restrictions.eq("country.countryid", countryId))
										.list();
		
		return stateList;
	}
	
	@SuppressWarnings("unchecked")
	@Transactional
	public List<City> getAssociatedCityList(Serializable cityId){
		List<City> cityList = sessionFactory
										.getCurrentSession()
										.createCriteria(City.class,"city")
										.createAlias("city.state", "state")
										.setFetchMode("state", FetchMode.JOIN)
										.add(Restrictions.eq("state.stateid", cityId))
										.list();
		
		return cityList;
	}
}
